package org.example;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.jsonSchema.JsonSchema;
import com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper;
import org.example.model.AssessmentReport;
import org.springframework.ai.util.json.schema.JsonSchemaGenerator;
import org.springframework.util.ReflectionUtils;

import java.lang.reflect.Method;

/**
 * 示例主类 - 可能是项目初始阶段创建的示例文件
 * 包含一个简单的循环示例和一些IDE提示
 * 注意：在Spring Boot应用中，此文件不是实际的应用入口点，SpringAiDemoApplication才是
 */
public class Main {

    /**
     * 示例主方法 - 演示基本的Java循环和输出
     * @param args 命令行参数
     */
    public static void main(String[] args) throws JsonProcessingException {

        Method method =
                ReflectionUtils.findMethod(
                        ReportResultService.class, "writeEvaluationToFile", AssessmentReport.class);

        System.out.println(JsonSchemaGenerator.generateForMethodInput(method));

        ObjectMapper mapper = new ObjectMapper();
        SchemaFactoryWrapper wrapper = new SchemaFactoryWrapper();

        // 生成JSON Schema
        mapper.acceptJsonFormatVisitor(AssessmentReport.class, wrapper);
        JsonSchema schema = wrapper.finalSchema();

        // 转换为JSON字符串并打印
        String schemaJson = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(schema);
        System.out.println(schemaJson);
    }
}
